package com.example.common.util;

import java.math.BigDecimal;
import java.util.regex.Pattern;

/**
 * @description: 工具类
 * @author: uu
 * @data: 2023/7/12 下午 04:44
 * @version: v1.0
 */
public class CommonUtil {
    /*处理pageNo*/
    public static int defaultPageNO(Integer pageNo){
        int pNo = pageNo;
        if (pageNo == null || pageNo < 1){
            pNo = 1;
        }
        return pNo;
    }
    /*处理pageSize*/
    public static int defaultPageSize(Integer pageSize){
        int pSize = pageSize;
        if (pageSize == null || pageSize < 1){
            pSize = 1;
        }
        return pSize;
    }

    /*手机号数据脱敏*/
    public static String desensitiZation(String phone){
        String result = "***********";
        if (phone != null && phone.trim().length() == 11){
            result = phone.substring(0,3) +"******" + phone.substring(9);
        }
        return result;
    }

    /*手机号码正则表达式验证*/
    public static Boolean checkPhone(String phone){
        boolean flag = false;
        if (phone != null && phone.length() == 11){
            //^1[1-9]\\d{9}$
            flag = Pattern.matches("^1[1-9]\\d{9}", phone);
        }
        return flag;
    }

    /*DigDecimal 比较*/
    public static Boolean get(BigDecimal n1, BigDecimal n2){
        if (n1 == null || n2 == null){
            throw new RuntimeException("BigDeciaml 参数不正确");
        }
        return n1.compareTo(n2) >= 0;
    }

}
